home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 355_03 / slk3.exe / TEST / DCLTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-04  |  11.8 KB  |  658 lines

  1. /*
  2.     Tests of declarations that SPP must handle cleanly.
  3.  
  4.     source:  dcltest.c
  5.     started: April 4, 1988
  6.     version:
  7.         February 17, 1989
  8.         March 24, 1989 struct test added
  9.         June 27, 1989
  10.             second struct test added
  11.             nested comment test added
  12.             macro overflow test added
  13.             regression tests added
  14.         August 4, 1989
  15.             union b changed to union bb.
  16. */
  17.  
  18. #include "\sherlock\sl.h"
  19.  
  20. struct a {int sa;};
  21. struct b {int sb;};
  22. union bb {int sb;};
  23.  
  24. /* Old style. */
  25. int types1A(
  26. c, sc, uc, sh, ssh, shi, sshi,
  27. ac, asc, auc, ash, assh, ashi, asshi)
  28. char c;
  29. signed char sc;
  30. unsigned char uc;
  31. short sh;
  32. signed short ssh;
  33. short int shi;
  34. signed short int sshi;
  35. char ac[1];
  36. signed char asc[];
  37. unsigned char auc[10000];
  38. short ash[];
  39. signed short assh[2];
  40. short int ashi[];
  41. signed short int asshi[100];
  42. {
  43.     printf("(%c, %c, %c, %d, %d, %d, %d)\n",
  44.         c, sc, uc, sh, ssh, shi, sshi);
  45.     printf("(%p, %p, %p, %p, %p, %p, %p)\n",
  46.         ac, asc, auc, ash, assh, ashi, asshi);
  47. }
  48.  
  49. /* New style. */
  50. int types1B(
  51. char c,
  52. signed char sc,
  53. unsigned char uc,
  54. short sh,
  55. signed short ssh,
  56. short int shi,
  57. signed short int sshi,
  58. char ac[2],
  59. signed char asc[3],
  60. unsigned char auc[],
  61. short ash[4],
  62. signed short assh[5],
  63. short int ashi[],
  64. signed short int asshi[])
  65. {
  66.     printf("(%c, %c, %c, %d, %d, %d, %d)\n",
  67.         c, sc, uc, sh, ssh, shi, sshi);
  68.     printf("(%p, %p, %p, %p, %p, %p, %p)\n",
  69.         ac, asc, auc, ash, assh, ashi, asshi);
  70. }
  71.  
  72. /* Direct typedefs. */
  73. typedef char tc;
  74. typedef int  ti;
  75. typedef short tsh;
  76.  
  77. typedef signed char tsc;
  78. typedef unsigned char tuc;
  79. typedef signed short tssh;
  80. typedef short int tshi;
  81. typedef signed short int tsshi;
  82.  
  83. /* Multi-level typedefs. */
  84. typedef signed tc tstc;
  85. typedef unsigned tc tutc;
  86. typedef signed tsh tstsh;
  87. typedef short ti tshti;
  88. typedef signed short ti tsshti;
  89.  
  90. typedef short ti * tshtip;
  91. typedef tsshti * tsshtip;
  92.  
  93. /* Old style with typedefs. */
  94. tssh types1C(    c, sc, stc, uc, utc, sh, ssh, stsh,
  95.         shi, shti, sshi, sshti, shtip, sshtip,
  96.         ac, asc, astc, auc, autc, ash, assh, astsh,
  97.         ashi, ashti, asshi, asshti, ashtip, asshtip)
  98. tc c, ac[1];
  99. tsc sc, asc[2]; tstc stc, astc[];
  100. tuc uc, auc[]; tutc utc, autc[3];
  101. tsh sh, ash[4];
  102. tssh ssh, assh[]; tstsh stsh, astsh[5];
  103. tshi shi, ashi[6]; tshti shti, ashti[7];
  104. tsshi sshi, asshi[]; tsshti sshti, asshti[];
  105. tshtip shtip, ashtip[100];
  106. tsshtip sshtip, asshtip[101];
  107. {
  108.     printf("(%c, %c, %c, %c, %c, %d, %d, %d, %d, %d, %d, %d, %p, %p)\n",
  109.         c, sc, stc, uc, utc,
  110.         sh, ssh, stsh, shi, shti,
  111.         sshi, sshti, shtip, sshtip);
  112.     printf("(%p, %p, %p, %p, %p, %p, %p, %p, %p, %p, %p, %p, %p, %p)\n",
  113.         ac, asc, astc, auc, autc,
  114.         ash, assh, astsh, ashi, ashti,
  115.         asshi, asshti, ashtip, asshtip);
  116.  
  117.     return 1;
  118. }
  119.  
  120. /* New style with typedefs. */
  121. tsshi types1D(
  122. tc c,
  123. tsc sc,
  124. tuc uc,
  125. tsh sh,
  126. tssh ssh,
  127. tshi shi,
  128. tsshi sshi)
  129. {
  130.     printf("(%c, %c, %c, %d, %d, %d, %d)\n",
  131.         c, sc, uc, sh, ssh, shi, sshi);
  132.  
  133.     return 1;
  134. }
  135.  
  136. /* Old Style. */
  137. int types2A(ush, ushi, i, s, si, u, ui)
  138. unsigned short ush;
  139. unsigned short int ushi;
  140. int i;
  141. signed s;
  142. signed int si;
  143. unsigned u;
  144. unsigned int ui;
  145. {
  146.     printf("(%u, %u, %d, %d, %d, %u, %u)\n",
  147.         ush, ushi, i, s, si, u, ui);
  148. }
  149.  
  150. /* New Style. */
  151. int types2B(
  152. unsigned short ush,
  153. unsigned short int ushi,
  154. int i,
  155. signed s,
  156. signed int si,
  157. unsigned u,
  158. unsigned int ui)
  159. {
  160.     printf("(%u, %u, %d, %d, %d, %u, %u)\n",
  161.         ush, ushi, i, s, si, u, ui);
  162. }
  163.  
  164. typedef unsigned short tush;
  165. typedef unsigned short int tushi;
  166. typedef signed ts;
  167. typedef signed int tsi;
  168. typedef unsigned tu;
  169. typedef unsigned int tui;
  170.  
  171. /* Old Style with typedefs */
  172. tush types2C(ush, ushi, i, s, si, u, ui)
  173. tush ush;
  174. tushi ushi;
  175. ti i;
  176. ts s;
  177. tsi si;
  178. tu u;
  179. tui ui;
  180. {
  181.     printf("(%u, %u, %d, %d, %d, %u, %u)\n",
  182.         ush, ushi, i, s, si, u, ui);
  183.  
  184.     return 0xffff;
  185. }
  186.  
  187. /* New Style with typedefs */
  188. tushi types2D(
  189. tush ush,
  190. tushi ushi,
  191. ti i,
  192. ts s,
  193. tsi si,
  194. tu u,
  195. tui ui)
  196. {
  197.     printf("(%u, %u, %d, %d, %d, %u, %u)\n",
  198.         ush, ushi, i, s, si, u, ui);
  199.  
  200.     return 0xffff;
  201. }
  202.  
  203.  
  204. /* Old Style. */
  205. unsigned types3A(l, sl, li, sli, ul, uli)
  206. long l;
  207. signed long sl;
  208. long int li;
  209. signed long int sli;
  210. unsigned long ul;
  211. unsigned long int uli;
  212. {
  213.     printf("(%ld, %ld, %ld, %ld, %lu, %lu)\n",
  214.         l, sl, li, sli, ul, uli);
  215.  
  216.     return 0xffff;
  217. }
  218.  
  219. /* New Style. */
  220. unsigned long types3B(
  221. long l,
  222. signed long sl,
  223. long int li,
  224. signed long int sli,
  225. unsigned long ul,
  226. unsigned long int uli)
  227. {
  228.     printf("(%ld, %ld, %ld, %ld, %lu, %lu)\n",
  229.         l, sl, li, sli, ul, uli);
  230.  
  231.     return 0xffffffff;
  232. }
  233.  
  234. typedef long tl;
  235. typedef signed long tsl;
  236. typedef long int tli;
  237. typedef signed long int tsli;
  238. typedef unsigned long tul;
  239. typedef unsigned long int tuli;
  240.  
  241. /* Old Style with typedefs. */
  242. tul types3C(l, sl, li, sli, ul, uli)
  243. tl l;
  244. tsl sl;
  245. tli li;
  246. tsli sli;
  247. tul ul;
  248. tuli uli;
  249. {
  250.     printf("(%ld, %ld, %ld, %ld, %lu, %lu)\n",
  251.         l, sl, li, sli, ul, uli);
  252.  
  253.     return 0xffffffff;    
  254. }
  255.  
  256. /* New Style with typedefs. */
  257. tuli types3D(
  258. tl l,
  259. tsl sl,
  260. tli li,
  261. tsli sli,
  262. tul ul,
  263. tuli uli)
  264. {
  265.     printf("(%ld, %ld, %ld, %ld, %lu, %lu)\n",
  266.         l, sl, li, sli, ul, uli);
  267.  
  268.     return 0xffffffff;
  269. }
  270.  
  271. /* Old Style. */
  272. float types4A(f, d, ld, st, un, e)
  273. float f;
  274. double d;
  275. long double ld;
  276. struct a st;
  277. union bb un;
  278. enum en e;
  279. {
  280.     printf("(%g, %g, %g, %p, %p, %d)\n",
  281.         f, d, ld, st, un, e);
  282.  
  283.     printf("=(%p, %p)\n", &st, &un); /* 3/24/89 */
  284.  
  285.     return (float) 0.0;
  286. }
  287.  
  288. /* New Style. */
  289. double types4B(
  290. float f,
  291. double d,
  292. long double ld,
  293. struct a st,
  294. union bb un,
  295. enum en e)
  296. {
  297.     printf("(%g, %g, %g, %p, %p, %d)\n",
  298.         f, d, ld, st, un, e);
  299.  
  300.     printf("=(%p, %p)\n", &st, &un); /* 3/24/89 */
  301.  
  302.     return (double) 0.0;
  303. }
  304.  
  305. typedef float tf;
  306. typedef double td;
  307. typedef long double tld;
  308. typedef struct a tst;
  309. typedef union bb tun;
  310. typedef enum en te;
  311.  
  312. /* Old Style with typedefs. */
  313. tf types4C(f, d, ld, st, un, e)
  314. tf f;
  315. td d;
  316. tld ld;
  317. tst st;
  318. tun un;
  319. te e;
  320. {
  321.     printf("(%g, %g, %g, %p, %p, %d)\n",
  322.         f, d, ld, st, un, e);
  323.  
  324.     return 0.1;
  325. }
  326.  
  327. /* New Style with typedefs. */
  328. td types4D(
  329. tf f,
  330. td d,
  331. tld ld,
  332. tst st,
  333. tun un,
  334. te e)
  335. {
  336.     printf("(%g, %g, %g, %p, %p, %d)\n",
  337.         f, d, ld, st, un, e);
  338.  
  339.     return (double) 0.1;
  340. }
  341.  
  342. /* Old Style. */
  343. char * types5A(c, s, p)
  344. char c;
  345. char * s;
  346. char ** p;
  347. {
  348.     printf("(%c, %s, %p)\n", c, s, p);
  349.  
  350.     return "abc";
  351. }
  352.  
  353. /* New Style. */
  354. char ** types5B(
  355. char c,
  356. char * s,
  357. char ** p)
  358. {
  359.     printf("(%c, %s, %p)\n", c, s, p);
  360.  
  361.     return ((char **) 0);
  362. }
  363.  
  364. typedef tc *     string1;
  365. typedef char *   string2;
  366. typedef string1 * tcpp1;
  367. typedef char **   tcpp2;
  368.  
  369. /* Old Style. */
  370. string1 types5C(c, s1, s2, p1, p2)
  371. tc c;
  372. string1 s1;
  373. string2 s2;
  374. tcpp1 p1;
  375. tcpp2 p2;
  376. {
  377.     printf("(%c, %s, %s, %p, %p)\n", c, s1, s2, p1, p2);
  378.  
  379.     return "abc";
  380. }
  381.  
  382. /* New Style. */
  383. tcpp1 types5D(
  384. tc c,
  385. string1 s1,
  386. string2 s2,
  387. tcpp1 p1,
  388. tcpp2 p2)
  389. {
  390.     printf("(%c, %s, %s, %p, %p)\n", c, s1, s2, p1, p2);
  391.  
  392.     return ((char **) 0);
  393. }
  394.  
  395. typedef int ta [25];
  396. typedef ta * tap;
  397.  
  398. /* Old Style. */
  399. ta * types6A(a, ap1, ap2)
  400. ta a;
  401. tap ap1;
  402. ta * ap2;
  403. {
  404.     printf("(%p, %p, %p)\n", a, ap1, ap2);
  405.  
  406.     return (ta *) 0;
  407. }
  408.  
  409. /* New Style. */
  410. ta * types6B(
  411. ta a,
  412. tap ap1,
  413. ta * ap2)
  414. {
  415.     printf("(%p, %p, %p)\n", a, ap1, ap2);
  416.  
  417.     return (ta *) 0;
  418. }
  419.  
  420. int a20;
  421. int * types7(void)
  422. {
  423.     return &a20;
  424. }
  425.  
  426. int types8(int (* func)(void))
  427. {
  428.     printf("%p", func);
  429.  
  430.     return 1;
  431. }
  432.  
  433. typedef int bool;
  434. typedef bool bool2;
  435.  
  436. bool types9A(b1)
  437. bool b1;
  438. {
  439.     printf("(%d)\n", b1);
  440.     return 1;
  441. }
  442.  
  443. bool2 type9B(bool b1, bool2 b2)
  444. {
  445.     printf("(%d, %d)\n", b1, b2);
  446.     return 1;
  447. }
  448.  
  449. enum hue {chartreuse, burgundy, claret=20, winedark};
  450. enum hue types9(void)
  451. {
  452.     return chartreuse;
  453. }
  454.  
  455. /*
  456.     More tests of weird and wonderful declarations.
  457.     See pages 244 and 245 of Turbo C User's Guide.
  458. */
  459.  
  460. /* Page 244. */
  461. int f1();
  462. int * p1;
  463. int *f2();
  464. int far *p2;
  465. int far *f3();
  466. int *far f4();
  467. int (*fp1) (int);
  468. int (*fp2) (int *ip);
  469. int (far *fp3) (int far *ip);
  470. int (far *list[5]) (int far *ip);
  471. int (far *gopher(int (far * fp[5]) (int far * ip))) (int far *ip);
  472.  
  473. /* Page 245. */
  474. int f1();
  475. typedef int *intptr;
  476. intptr p1;
  477. typedef int far * farptr;
  478. farptr p2;
  479. typedef int (fncptr1) (int);
  480. fncptr1 fp10;
  481. typedef int (*fncptr2) (intptr);
  482. fncptr2 fp11;
  483. typedef int (far *ffptr) (farptr);
  484. ffptr fp12;
  485. typedef ffptr ffplist [5];
  486. ffplist list;
  487. ffptr gopher(ffplist);
  488.  
  489. int fv(void), *fip(), (*pfi)();
  490. int (*fpfi(int(*)(long), int))(int,...);
  491. int (*apfi[3]) (int *x, int *y);
  492.  
  493. /* Array modifications from page 244. */
  494. int * ap1 [10];
  495. int (* pa1) [11];
  496. int (*afp1) (int[]);
  497. int (*afp2) (int *ip[4]);
  498. int (*alist[5]) (int far *aip[5]);
  499. int (far *agopher(int (far * fp[5]) (int far * ip[]))) (int far *ip[8]);
  500.  
  501. /* Array modifications from page 245. */
  502. typedef int * aintptr[20];
  503. aintptr ap1A[2];
  504. typedef int far * afarptr[3];
  505. afarptr ap2;
  506. typedef int (*afncptr1[25]) (int[]);
  507. afncptr1 afp10;
  508. typedef int (*afncptr2) (aintptr[]);
  509. afncptr2 afp11[26];
  510. typedef int (far *affptr) (afarptr[]);
  511. affptr afp12[27];
  512. typedef ffptr affplist [5];
  513. affplist a2list[28];
  514. affptr a2gopher(affplist[]);
  515.  
  516. /* 6/22/89 */
  517. void fred(int []);
  518. struct fred2 {int i; int v[3];};
  519. struct fred2 t = {1, {0,0,0}};
  520.  
  521. /* 6/27/89 */
  522. struct s {int i; char v[3];};
  523. struct s t1;
  524. typedef struct s tstruct;
  525.  
  526. /* Old Style */
  527. struct s
  528. struct_testA(t2, t3, t4, t5, at1, at2)
  529. struct s t2, *t3;
  530. tstruct t4, *t5;
  531. struct s at1[2];
  532. tstruct at2[3];
  533. {
  534.     printf("%p, %p, %p, %p, %p %p\n", &t2, t3, &t4, t5, at1, at2);
  535.     return t1;
  536. }
  537.  
  538. /* New Style */
  539. struct s
  540. struct_testB(
  541. struct s t2,
  542. struct s *t3,
  543. tstruct t4,
  544. tstruct *t5,
  545. struct s at1[],
  546. tstruct at2[])
  547. {
  548.     printf("%p, %p, %p, %p, %p, %p\n", &t2, t3, &t4, t5, at1, at2);
  549.     return t1;
  550. }
  551.  
  552. /* Old Style with typedefs */
  553. tstruct
  554. struct_testA2(t2, t3, t4, t5)
  555. tstruct t2, *t3;
  556. struct s *t4, t5;
  557. {
  558.     printf("%p, %p, %p, %p\n", &t2, t3, t4, &t5);
  559.     return t1;
  560. }
  561.  
  562. /* New Style with typedefs */
  563. tstruct
  564. struct_testB2(
  565. tstruct t2,
  566. tstruct *t3,
  567. struct s *t4,
  568. struct s t5)
  569. {
  570.     printf("%p, %p, %p, %p\n", &t2, t3, t4, &t5);
  571.     return t1;
  572. }
  573.  
  574. union u {int i; char v[3];};
  575. union u ut;
  576. typedef union u tunion;
  577.  
  578. /* Old Style */
  579. union u
  580. union_testA(u2, u3, u4, u5)
  581. union u u2, *u3;
  582. tunion u4, *u5;
  583. {
  584.     printf("%p, %p, %p, %p\n", &u2, u3, &u4, u5);
  585.     return ut;
  586. }
  587.  
  588. /* New Style */
  589. union u
  590. union_testB(
  591. union u u2,
  592. union u *u3,
  593. tunion u4,
  594. tunion *u5)
  595. {
  596.     printf("%p, %p, %p, %p\n", &u2, u3, &u4, u5);
  597.     return ut;
  598. }
  599.  
  600. /* Old Style with typedefs */
  601. tunion
  602. union_testA2(u2, u3, u4, u5)
  603. tunion u2, *u3;
  604. union u u4, *u5;
  605. {
  606.     printf("%p, %p, %p, %p\n", &u2, u3, &u4, u5);
  607.     return ut;
  608. }
  609.  
  610. /* New Style with typedefs */
  611. tunion
  612. union_testB2(
  613. tunion u2,
  614. tunion *u3,
  615. union u *u4,
  616. union u u5)
  617. {
  618.     printf("%p, %p, %p, %p\n", &u2, u3, u4, &u5);
  619.     return ut;
  620. }
  621.  
  622. /* ---------------------------------- */
  623. /*
  624. /* ---------------------------------- */
  625.  
  626. /* comment */
  627.  
  628. void foo()
  629. {}
  630.  
  631. typedef unsigned short word;
  632. typedef struct {
  633.     word st_col;    /* starting column of line.    */
  634.     word st_row;    /* starting row.        */
  635.     word end_col;    /* ending column.        */
  636.     word end_row;    /* ending row.            */
  637.     word st_arcol;    /* starting col of arrorhead.    */
  638.     word st_arrow;    /* starting row.        */
  639.     word end_arcol;    /* ending col.            */
  640.     word end_arrow;    /* ending row.            */
  641. } line;
  642.  
  643. #define min(a,b) ( ((a) < (b)) ? (a) : (b) )
  644. #define max(a,b) ( ((a) > (b)) ? (a) : (b) )
  645.  
  646. extern void generate_line(line *l)
  647. {
  648. word min_row_ext, min_col_ext, max_row_ext, max_col_ext;
  649.     min_row_ext = 0;
  650.     min_col_ext = 1;
  651.     max_row_ext = 3;
  652.     max_col_ext = 5;
  653.  min_row_ext = min(min_row_ext, min(l->st_arrow, min(l->end_arrow, min(l->st_row, l->end_row))));
  654.  min_col_ext = min(min_col_ext, min(l->st_arcol, min(l->end_arcol, min(l->st_row, l->end_col))));
  655.  max_row_ext = max(max_row_ext, max(l->st_arrow, max(l->end_arrow, max(l->st_row, l->end_row))));
  656.  max_col_ext = max(max_col_ext, max(l->st_arcol, max(l->end_arcol, max(l->st_row, l->end_col))));
  657. }
  658.